from django.http import HttpResponse
from django.shortcuts import render


def she_bao(request):
    if request.method == 'GET':
        return render(request, 'shebao.html')
    elif request.method == 'POST':
        base = request.POST.get('income', '0')
        base = base if base else '0'
        base = float(base)
        is_city = request.POST.get('is_city')
        return render(request, 'shebao.html', locals())


def test_form(request):
    '此视图函数用于示意form表单的提交'
    if request.method == 'GET':
        # 返回表单
        dic = dict(request.GET)
        nickname = request.GET.get('nickname', '')
        print('dic=', dic)
        print('nickname=', nickname)
        return render(request, 'myform.html')
    elif request.method == 'POST':
        # 返回表单提交内容的结果
        dic = dict(request.POST)
        print('dic=', dic)
        # fav = request.POST.get('fav')
        fav = request.POST.getlist('fav')
        return HttpResponse("没有结果")
